// import Vue from 'vue'
import axios from 'axios'
import axiosRetry from 'axios-retry'
import {
  handleAuthError,
  handleGeneralError,
  handleNetworkError
} from '@/src/utils/error'

const client = axios.create({
  // 你的配置
})

// 当请求失败后，自动重新请求，只有3次失败后才真正失败
axiosRetry(client, { retries: 3 })

axios.interceptors.response.use(
  (response) => {
    if (response.status !== 200) return Promise.reject(response.data)

    handleAuthError(response.data.errno)
    handleGeneralError(response.data.errno, response.data.errmsg)

    return response
  },
  (err) => {
    handleNetworkError(err.response.status)
    Promise.reject(err.response)
  }
)
